From cdfc2d3cb59ee7ffcdb09411a9fd3f554c2295c7 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Wed, 26 Apr 2006 12:45:15 +0000 Subject: [PATCH] Filter and format settings are now saved to registry. --- gpsbabel/win32/gui-2/GPSBabelGUI.dof | 12 +- gpsbabel/win32/gui-2/about.dfm | Bin 3499 -> 3504 bytes gpsbabel/win32/gui-2/common.pas | 24 ++-- gpsbabel/win32/gui-2/filter.dfm | Bin 7939 -> 8303 bytes gpsbabel/win32/gui-2/filter.pas | 167 +++++++++++++++++++++++++-- gpsbabel/win32/gui-2/gpsbabel.iss | 2 +- gpsbabel/win32/gui-2/options.dfm | Bin 1293 -> 1313 bytes gpsbabel/win32/gui-2/options.pas | 163 +++++++++++++++++++++++++- gpsbabel/win32/gui-2/utils.pas | 38 +++++- 9 files changed, 373 insertions(+), 33 deletions(-) diff --git a/gpsbabel/win32/gui-2/GPSBabelGUI.dof b/gpsbabel/win32/gui-2/GPSBabelGUI.dof index 74c076f4b..f3d14f909 100644 --- a/gpsbabel/win32/gui-2/GPSBabelGUI.dof +++ b/gpsbabel/win32/gui-2/GPSBabelGUI.dof @@ -57,9 +57,9 @@ AutoIncBuild=0 MajorVer=0 MinorVer=2 Release=3 -Build=2 +Build=4 Debug=0 -PreRelease=1 +PreRelease=0 Special=0 Private=0 DLL=0 @@ -68,13 +68,13 @@ CodePage=1252 [Version Info Keys] CompanyName=GPSBabel Makers FileDescription=GPSBabel Windows Frontend -FileVersion=0.2.3.2 -InternalName=GPSBabelGUI-2 -LegalCopyright=(C) 2005 Olaf Klein (O.B.Klein@T-Online.de) +FileVersion=0.2.3.4 +InternalName= +LegalCopyright=(C) 2005-2006 Olaf Klein (O.B.Klein@T-Online.de) LegalTrademarks= OriginalFilename=GPSBabelGUI.exe ProductName=GPSBabel -ProductVersion=1.2.8-beta01182006 +ProductVersion=1.2.8-beta20060420_ds Comments=internal test build [HistoryLists\hlConditionals] Count=1 diff --git a/gpsbabel/win32/gui-2/about.dfm b/gpsbabel/win32/gui-2/about.dfm index fb5bc04878fbf0189aaa28bd6542a2d23bad0aed..5e235e3c7ff4b25eb9fed9e95e33a5f18f1be543 100644 GIT binary patch delta 55 zcmZ22y+K;wKNmxYTad4#lYeLkgMq-@jRJSrC9ItD3o45;(=$pGG@LaRj0_A+b%BK0 J=Kt(#SOMO%5aj>> delta 50 zcmdlWy;@q}KNmxYTad4#lYeLkgMq+|jRJSrg-xCF3o45;(=$pGG@LaRj0_A+H?wf8 GVFdt=6AtG9 diff --git a/gpsbabel/win32/gui-2/common.pas b/gpsbabel/win32/gui-2/common.pas index 80baf50b8..53d632743 100644 --- a/gpsbabel/win32/gui-2/common.pas +++ b/gpsbabel/win32/gui-2/common.pas @@ -21,14 +21,14 @@ unit common; interface uses - Windows, SysUtils, Classes, Messages, Controls, StdCtrls, Inifiles; + Windows, SysUtils, Classes, Messages, Controls, StdCtrls; const OTypes: array[0..6] of PChar = ('unknown', 'integer', 'float', 'string', 'boolean', 'file', 'outfile'); gpsbabel_knows_inifile: Boolean = False; - gpsbabel_ini: TInifile = nil; +//gpsbabel_ini: TInifile = nil; resourcestring SGPSBabelURL = 'http://www.gpsbabel.org'; @@ -45,7 +45,6 @@ var gpsbabel_minor, gpsbabel_major, gpsbabel_release: Integer; SGPSBabelGUIVersion: string; CFixedFileinfo: TVSFixedFileInfo; - gpsbabel_inifile: TInifile; const WM_STARTUP = WM_USER + 1; @@ -252,12 +251,7 @@ begin 1: opt.format := string(cin); 2: - begin - opt.name := string(cin); - s := gpsbabel_ini.ReadString(opt.Format, opt.Name, #01); - if (s <> #01) then - opt.def := StrNew(PChar(s)); - end; + opt.name := string(cin); 3: opt.hint := string(cin); 4: @@ -281,11 +275,17 @@ begin if (cin^ <> #0) then opt.max := StrNew(cin); end; - + index := index + 1; cin := cend + 1; end; + if (opt.name = 'snlen') and (opt.gbdef = nil) then + begin + opt.gbdef := StrNew('10'); + opt.def := opt.gbdef; + end; + index := Self.IndexOf(opt.format); if (index >= 0) then list := TStringList(Self.Objects[index]) @@ -537,6 +537,7 @@ begin end; end; +(* function Open_gpsbabel_ini(): TInifile; var s: string; @@ -549,11 +550,12 @@ begin else Result := TIniFile.Create(s) end; +*) initialization gpsbabel_exe := SysUtils.ExtractFilePath(ParamStr(0)) + SGPSBabelExeFilename; SGPSBabelGUIVersion := GetFileVersion(ParamStr(0)); - gpsbabel_ini := Open_gpsbabel_ini(); +//gpsbabel_ini := Open_gpsbabel_ini(); end. diff --git a/gpsbabel/win32/gui-2/filter.dfm b/gpsbabel/win32/gui-2/filter.dfm index d3faa1abd52f31f14551fea96572182b14a55349..c9967bf7398c43ac24f0fe57b6155f13b45a4adf 100644 GIT binary patch delta 503 zcmZp+d+%WVpNk>HEy&l+(s9>M#d?dd6^QJ1O-!5LW&ZTvqLgVa#F(*b4n*yvgB|wzh(fb zXG+-omL;8$QFwAF+bKqo%?j*_jEtg_71*UF$8hXo6x%G$Daj_z8RDFgnw;&FU%``{ z1UAeqvm&*4@&gu;`b0L5)XemZ5+*?wkIcLhHjUuQypoL6;>@a41^0kpg*1>#1&x4! zU>yY)pn#5ov5Ss^k&7m~b7DbBW_}(UCtMjvNMe$IQA%nNlOO{F!ctzSrOx@KMa8LL z?=n?@U0=akAD)>~lEH-T3JD}vB!jgnlmWe-S`4?94PqL?N+Dz`Vg3v*NKH+F1TZwf nDp*l$w1#_J9LdUJkT!H1S;2-OEEM0Y$G@DJF=g{LAzdB-(IcHx delta 151 zcmaFw&}?V@pNk>HEy&l+(u3KhKNoo-%oWz($>Ct)0I6iE*!-C# vosm&+ax~j1Mxo7W?23$&quBT-hjAQZ6xl4xDap2Zj=)l8#`MijBDy>P7j7-1 diff --git a/gpsbabel/win32/gui-2/filter.pas b/gpsbabel/win32/gui-2/filter.pas index ddc92b92a..18f963e85 100644 --- a/gpsbabel/win32/gui-2/filter.pas +++ b/gpsbabel/win32/gui-2/filter.pas @@ -23,14 +23,14 @@ interface uses gnugettext, gnugettextDx, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, - StdCtrls, ComCtrls, Buttons, Mask, ExtCtrls, + StdCtrls, ComCtrls, Buttons, Mask, ExtCtrls, Registry, common, utils; type TfrmFilter = class(TForm) gbTracks: TGroupBox; cbTrackTitle: TCheckBox; - edTrackTitle: TEdit; + edTrackTitleValue: TEdit; cbTrackSplit: TCheckBox; cbTrackTime: TCheckBox; udTimeHours: TUpDown; @@ -82,6 +82,9 @@ type edWayptRadiusLon: TEdit; cbTrackRangeTimeZone: TCheckBox; BitBtn2: TBitBtn; + cbTrackFixes: TCheckBox; + cbTrackCourse: TCheckBox; + cbTrackSpeed: TCheckBox; procedure cbTrackTimeClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure cbTrackTitleClick(Sender: TObject); @@ -110,6 +113,10 @@ type function AllValid: Boolean; function ValidateNumerical(AEdit: TCustomEdit; AMin, AMax: Extended): Boolean; procedure ChangeCheckBoxesChecked(AComponent: TComponent; Restore: Boolean = False); + procedure LoadSettingsFromInifile(); + procedure LoadSettingsFromRegistry(); + procedure StoreSettingsToInifile(); + procedure StoreSettingsToRegistry(); public { Public-Deklarationen } function CmdLine: string; @@ -217,6 +224,15 @@ begin gpsbabel_version]); gbTracks.ShowHint := True; end; + + if not(gpsbabel_knows_inifile) then + begin + cbTrackFixes.Enabled := False; + cbTrackCourse.Enabled := False; + cbTrackSpeed.Enabled := False; + end; +//LoadSettingsFromInifile(); + LoadSettingsFromRegistry(); end; function TfrmFilter.ValidateNumerical(AEdit: TCustomEdit; AMin, AMax: Extended): Boolean; @@ -276,7 +292,7 @@ end; procedure TfrmFilter.cbTrackTitleClick(Sender: TObject); begin - edTrackTitle.Enabled := cbTrackTitle.Checked; + edTrackTitleValue.Enabled := cbTrackTitle.Checked; end; function TfrmFilter.CmdLine: string; @@ -331,7 +347,7 @@ begin begin Result := Format('%s -x %s', [Result, 'track']); if cbTrackTitle.Checked then - Result := Format('%s,title="%s"', [Result, edTrackTitle.Text]); + Result := Format('%s,title="%s"', [Result, edTrackTitleValue.Text]); if cbTrackTime.Checked then begin @@ -359,7 +375,6 @@ begin else dt_bias := 0.0; - if cbTrackStart.Checked then begin dt := Int(dtpTrackStartDate.DateTime) + Frac(dtpTrackStartTime.DateTime) + dt_bias; @@ -374,6 +389,12 @@ begin Result, FormatDateTime('yyyymmddhhnnss', dt)]); end; + if cbTrackFixes.Checked then + Result := Format('%s,fix', [Result]); + if cbTrackCourse.Checked then + Result := Format('%s,course', [Result]); + if cbTrackSpeed.Checked then + Result := Format('%s,speed', [Result]); end; if AnyChecked(gbRoutes) then @@ -419,7 +440,12 @@ end; procedure TfrmFilter.btnOKClick(Sender: TObject); begin - if AllValid then ModalResult := mrOK; + if AllValid then + begin +// StoreSettingsToInifile(); + StoreSettingsToRegistry(); + ModalResult := mrOK; + end; end; procedure TfrmFilter.cbTrackStartClick(Sender: TObject); @@ -537,7 +563,134 @@ end; procedure TfrmFilter.BitBtn2Click(Sender: TObject); begin - WinOpenURL(readme_html_path + '#id274853'); + WinOpenURL(readme_html_path + '#filters'); +end; + +procedure TfrmFilter.LoadSettingsFromInifile(); +var + c: TComponent; + i: Integer; + l: TStrings; + s: string; +begin +(* + l := TStringList.Create; + try + gpsbabel_ini.ReadSection('GPSBabelGUI', l); + for i := 0 to l.Count - 1 do + begin + s := l.Strings[i]; + c := SELF.FindComponent('cb' + s); + if (c <> nil) and (c is TCheckbox) then + TCheckbox(c).Checked := (gpsbabel_ini.ReadString('GPSBabelGUI', s, '0') <> '0'); + end; + edTrackTitleValue.Text := gpsbabel_ini.ReadString('track', 'title', + edTrackTitleValue.Text); + edRoutesSimplifyMaxPoints.Text := gpsbabel_ini.ReadString('simplify', 'count', + edRoutesSimplifyMaxPoints.Text); + finally + l.Free; + end; +*) +end; + +procedure TfrmFilter.StoreSettingsToInifile(); +var + i: Integer; + c: TComponent; +begin +(* + for i := 0 to SELF.ComponentCount - 1 do + begin + c := SELF.Components[i]; + if (c is TCheckBox) then + begin + if TCheckBox(c).Checked then + gpsbabel_ini.WriteString('GPSBabelGUI', Copy(TCheckbox(c).Name, 3, 256), '1') + else + gpsbabel_ini.DeleteKey('GPSBabelGUI', Copy(TCheckbox(c).Name, 3, 256)); + end; + end; + + if cbTrackTitle.Checked then + gpsbabel_ini.WriteString('track', 'title', edTrackTitleValue.Text) + else + gpsbabel_ini.DeleteKey('track', 'title'); + + if cbRouteSimplify.Checked then + gpsbabel_ini.WriteString('simplify', 'count', edRoutesSimplifyMaxPoints.Text) + else + gpsbabel_ini.DeleteKey('simplify', 'count'); +*) +end; + +procedure TfrmFilter.StoreSettingsToRegistry(); +var + i: Integer; + c: TComponent; + r: TRegistry; +begin + r := TRegistry.Create; + try + r.RootKey := HKEY_CURRENT_USER; + if not(r.OpenKey('\SOFTWARE\GPSBabel', True)) then Exit; + + for i := 0 to SELF.ComponentCount - 1 do + begin + c := SELF.Components[i]; + if (c is TCheckbox) then + r.WriteBool('filter:' + Copy(c.Name, 3, 256), TCheckBox(c).Checked) + else if (c is TEdit) then + r.WriteString('filter:' + Copy(c.Name, 3, 256), TEdit(c).Text); + end; + finally + r.Free; + end; +end; + +procedure TfrmFilter.LoadSettingsFromRegistry(); +var + i: Integer; + c: TComponent; + r: TRegistry; + s: string; + u: TUpDown; + + function ReadString(R: TRegistry; const Key, Def: string): string; + begin + if R.ValueExists(Key) then + Result := R.ReadString(Key) + else + Result := Def; + end; + +begin + r := TRegistry.Create; + try + r.RootKey := HKEY_CURRENT_USER; + if not(r.OpenKey('\SOFTWARE\GPSBabel', True)) then Exit; + + for i := 0 to SELF.ComponentCount - 1 do + begin + c := SELF.Components[i]; + try + if (c is TCheckbox) then + TCheckBox(c).Checked := r.ReadBool('filter:' + Copy(c.Name, 3, 256)) + else if (c is TEdit) then + begin + s := ReadString(r, 'filter:' + Copy(c.Name, 3, 256), TEdit(c).Text); + if HasUpDown(TEdit(c), u) then + u.Position := StrToInt(s) + else + TEdit(c).Text := s; + end; + except + on E: Exception do ; + end; + end; + finally + r.Free; + end; end; end. diff --git a/gpsbabel/win32/gui-2/gpsbabel.iss b/gpsbabel/win32/gui-2/gpsbabel.iss index 3bc9d7b38..0cf06c22c 100644 --- a/gpsbabel/win32/gui-2/gpsbabel.iss +++ b/gpsbabel/win32/gui-2/gpsbabel.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define Version "1.2.8" -#define Release "-beta20060405" +#define Release "-beta20060420_ds" [Setup] AppName=GPSBabel diff --git a/gpsbabel/win32/gui-2/options.dfm b/gpsbabel/win32/gui-2/options.dfm index 0fe28ae43b6d68a95066717430c7e491fe1436a2..a30cc841c7182acccbfd3df2c37f37f20866ac77 100644 GIT binary patch delta 54 zcmeC>TF52*pNk>HEy&kDAjH$(FPOnVfQNOXuoIIAyMLZ@PG)j8J6BRkp1(Jky*ZR= G2NM95z7KQ& delta 33 ocmZ3;)ypOPpNk>HEy&kDAjH$(FPOnV;0Mb_VJD`|nM^yF0H~D--~a#s diff --git a/gpsbabel/win32/gui-2/options.pas b/gpsbabel/win32/gui-2/options.pas index 0056924bb..a8953bddc 100644 --- a/gpsbabel/win32/gui-2/options.pas +++ b/gpsbabel/win32/gui-2/options.pas @@ -23,7 +23,7 @@ interface uses TypInfo, gnugettext, gnugettextDx, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, - StdCtrls, ExtCtrls, ComCtrls, Buttons, + StdCtrls, ExtCtrls, ComCtrls, Buttons, Registry, Common, delphi; type @@ -39,6 +39,7 @@ type procedure btnHelpClick(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); + procedure btnOKClick(Sender: TObject); private { Private declarations } FOpts: TStringList; @@ -54,6 +55,9 @@ type function ParseOptsLine(const Line: string; List: TStrings): Integer; procedure SetOpts(AList: TStringList); procedure SetOptsStr(const AValue: string); + procedure StoreOptionsToInifile(); + procedure StoreOptionsToRegistry(); + procedure LoadSettingsFromRegistry(); public { Public declarations } FFormat: string; @@ -198,7 +202,7 @@ begin chb.Top := xy.y; _xy := SetCaption(chb, dgettext(GPSBabel_Domain, o.Hint)); chb.Alignment := taRightJustify; - chb.Checked := False; +// chb.Checked := (gpsbabel_ini.ReadString(o.format, o.name, #1) <> #1); chb.Parent := pnOptions; chb.Hint := SysUtils.Format(_('Short "%s"'), [o.name]); @@ -267,6 +271,8 @@ begin i := btnCancel.Left - btnOK.Left; btnCancel.Left := pnBottom.Width - btnCancel.Width - btnHelp.Left; btnOK.Left := btnCancel.Left - i; + + LoadSettingsFromRegistry(); end; function TfrmOptions.GetOptsStr: string; @@ -657,4 +663,157 @@ begin ModalResult := mrCancel; end; +procedure TfrmOptions.StoreOptionsToInifile(); +var + i: Integer; + o: POption; + c: TComponent; + s, value: string; +begin +(* + for i := 0 to FOpts.Count - 1 do + begin + o := Pointer(FOpts.Objects[i]); + if (o.chb = nil) then Continue; + + if o.chb.AllowGrayed then + begin + if (o.chb.State = cbGrayed) then + begin + gpsbabel_ini.DeleteKey(o.format, o.name); + Continue; + end; + end + else if not(o.chb.Checked) then + begin + gpsbabel_ini.DeleteKey(o.format, o.name); + Continue; + end; + + if (o.edit = nil) then + begin + if o.chb.Checked then + value := '1' + else + value := '0'; + end + else value := GetStrProp(o.edit, 'Text'); + if (o.gbdef <> nil) and (StrPas(o.gbdef) = value) then + gpsbabel_ini.DeleteKey(o.format, o.name) + else + gpsbabel_ini.WriteString(o.format, o.name, value); + end; +*) +end; + +procedure TfrmOptions.StoreOptionsToRegistry(); +var + i: Integer; + o: POption; + c: TComponent; + s, key, value: string; + r: TRegistry; +begin + r := TRegistry.Create; + try + r.RootKey := HKEY_CURRENT_USER; + if not(r.OpenKey('\Software\GPSBabel', True)) then Exit; + + for i := 0 to FOpts.Count - 1 do + begin + o := Pointer(FOpts.Objects[i]); + if (o.chb = nil) then Continue; + + key := o.format + ':' + o.name; + + if o.chb.AllowGrayed then + begin + if (o.chb.State = cbGrayed) then + begin + r.DeleteValue(key); + Continue; + end; + end + else if not(o.chb.Checked) then + begin + r.DeleteValue(key); + Continue; + end; + + if (o.edit = nil) then + begin + if o.chb.Checked then + value := '1' + else + value := '0'; + end + else value := GetStrProp(o.edit, 'Text'); + if (o.gbdef <> nil) and (StrPas(o.gbdef) = value) then + r.WriteString(key, '(default)') + else + r.WriteString(key, value); + end; + finally + r.Free; + end; +end; + +procedure TfrmOptions.LoadSettingsFromRegistry(); +var + i: Integer; + o: POption; + c: TComponent; + s, key, value: string; + r: TRegistry; + u: TUpDown; +begin + r := TRegistry.Create; + try + r.RootKey := HKEY_CURRENT_USER; + if not(r.OpenKeyReadOnly('\Software\GPSBabel')) then Exit; + + for i := 0 to FOpts.Count - 1 do + begin + o := Pointer(FOpts.Objects[i]); + if (o.chb = nil) then Continue; + + key := o.format + ':' + o.name; + if not r.ValueExists(key) then Continue; + + Value := r.ReadString(key); + if (o.edit = nil) then + begin + if o.chb.AllowGrayed then + begin + if (value = '1') then + o.chb.State := cbChecked + else + o.chb.State := cbUnChecked; + end + else o.chb.Checked := True; + end + else + begin + o.chb.Checked := True; + if (value <> '(default)') then + begin + if HasUpDown(TEdit(o.edit), u) then + u.Position := StrToInt(value) + else + SetStrProp(o.edit, 'Text', value); + end; + o.edit.Enabled := True; + end; + end; + finally + r.Free; + end; +end; + +procedure TfrmOptions.btnOKClick(Sender: TObject); +begin +//StoreOptionsToInifile(); + StoreOptionsToRegistry(); +end; + end. diff --git a/gpsbabel/win32/gui-2/utils.pas b/gpsbabel/win32/gui-2/utils.pas index 2f8162db9..427502ae5 100644 --- a/gpsbabel/win32/gui-2/utils.pas +++ b/gpsbabel/win32/gui-2/utils.pas @@ -26,7 +26,8 @@ interface uses gnugettext, - Windows, SysUtils, Classes, Registry, ShellAPI; + Windows, SysUtils, Classes, StdCtrls, ComCtrls, + Registry, ShellAPI; type PBoolean = ^Boolean; @@ -54,11 +55,12 @@ procedure MakeFirstTranslation(AComponent: TComponent); function readme_html_path: string; +function HasUpDown(E: TEdit; var UpDown: TUpdown): Boolean; + implementation uses Forms, - StdCtrls, common; function GetShortName(const PathName: string): string; @@ -125,7 +127,7 @@ begin StartupInfo.cb := Sizeof (StartupInfo); StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; - StartupInfo.wShowWindow := SW_HIDE and SW_SHOWMINNOACTIVE; + StartupInfo.wShowWindow := {SW_HIDE or} SW_SHOWMINNOACTIVE; StartupInfo.hStdInput := GetStdHandle (STD_INPUT_HANDLE); StartupInfo.hStdOutput:= hWrite; StartupInfo.hStdError := hWrite; @@ -142,12 +144,14 @@ begin end; s := ''; + Error := 0; repeat Wait_Result := WaitforSingleObject(ProcessInfo.hProcess, 10); if PeekNamedPipe(hRead, nil, 0, nil, @BytesRead, nil) then begin - if (BytesRead > 0) then Application.ProcessMessages; + if (BytesRead > 0) then + Application.ProcessMessages; while (BytesRead > 0) do begin BytesDone := BytesRead; @@ -161,11 +165,12 @@ begin s := s + string(buffer); Dec(BytesRead, BytesDone); end; - end; + end end; until (Wait_Result = WAIT_OBJECT_0); - if not GetExitCodeProcess(ProcessInfo.hProcess, Error) then Error := 0; + if (Error = 0) then + if not GetExitCodeProcess(ProcessInfo.hProcess, Error) then Error := 0; if (Error <> 0) and (Error <> 1) then raise eGPSBabelError.CreateFmt(_('"gpsbabel.exe" returned error 0x%x (%d)'), [Error, Error]); @@ -400,6 +405,27 @@ begin Result := SGPSBabelURL + '/readme.html'; end; +function HasUpDown(E: TEdit; var UpDown: TUpdown): Boolean; +var + i: Integer; + c: TComponent; + o: TComponent; +begin + Result := False; + o := E.Owner; + for i := 0 to o.ComponentCount - 1 do + begin + c := o.Components[i]; + if (c is TUpDown) and (TUpDown(c).Associate = E) then + begin + UpDown := TUpDown(c); + Result := True; + Exit; + end; + end; +end; + + var hMutex: THandle; -- 2.30.2